home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / portage / bin / emerge-webrsync < prev    next >
Encoding:
Text File  |  2006-06-30  |  4.8 KB  |  165 lines

  1. #!/bin/bash
  2. # Copyright 1999-2006 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Id: /var/cvsroot/gentoo-src/portage/bin/Attic/emerge-webrsync,v 1.8.2.4 2005/02/26 11:22:38 carpaski Exp $
  5. # Author: Karl Trygve Kalleberg <karltk@gentoo.org>
  6. # Rewritten from the old, Perl-based emerge-webrsync script
  7.  
  8. # If PORTAGE_NICENESS is overriden via the env then it will
  9. # still pass through the portageq call and override properly.
  10. PORTAGE_NICENESS="$(/usr/lib/portage/bin/portageq envvar PORTAGE_NICENESS)"
  11. if [ -n "${PORTAGE_NICENESS}" ]; then
  12.     renice $PORTAGE_NICENESS $$ > /dev/null
  13. fi
  14.  
  15. source /usr/lib/portage/bin/isolated-functions.sh || exit 1
  16. FEATURES="$(/usr/lib/portage/bin/portageq envvar FEATURES)"
  17. GENTOO_MIRRORS="${GENTOO_MIRRORS} $(/usr/lib/portage/bin/portageq gentoo_mirrors)"
  18. PORTDIR="$(/usr/lib/portage/bin/portageq portdir)"
  19. FETCHCOMMAND="$(/usr/lib/portage/bin/portageq envvar FETCHCOMMAND)"
  20. USERLAND="$(/usr/lib/portage/bin/portageq envvar USERLAND)"
  21. DISTDIR="$(/usr/lib/portage/bin/portageq envvar PORTAGE_TMPDIR)/emerge-webrsync"
  22. PORTAGE_INST_UID="$(/usr/lib/portage/bin/portageq envvar PORTAGE_INST_UID)"
  23. PORTAGE_INST_GID="$(/usr/lib/portage/bin/portageq envvar PORTAGE_INST_GID)"
  24. if [ ! -d $DISTDIR ] ; then
  25.     mkdir -p $DISTDIR
  26. fi
  27.  
  28. cd "$DISTDIR"
  29.  
  30. found=0
  31. if [ "$1" == "-v" ] ; then
  32.     wgetops=
  33. else    
  34.     #this sucks.  probably better to do 1> /dev/null
  35.     #that said, waiting on the refactoring.
  36.     if [ "${FETCHCOMMAND/wget}" != "${FETCHCOMMAND}" ]; then
  37.         wgetops="-q"
  38.     elif [ "${FETCHCOMMAND/curl}" != "${FETCHCOMMAND}" ]; then
  39.         wgetops="-s -f"
  40.     fi
  41. fi
  42.  
  43. if type -p md5sum > /dev/null; then
  44.     md5_com='md5sum -c "${FILE}.md5sum"'
  45. elif type -p md5 > /dev/null; then
  46.     md5_com='[ "$(md5 -q ${FILE})" == "$(cut -d \  -f 1 ${FILE}.md5sum)" ]'
  47. else
  48.     echo "warning, unable to do md5 verification of the snapshot!"
  49.     echo "no suitable md5/md5sum binary was found!"
  50.     md5_com='true'
  51. fi
  52.  
  53. sync_local() {
  54.     echo Syncing local tree...
  55.     if type -p tarsync &> /dev/null; then
  56.         # tarsync doesn't take numeric uid/gid so we need to convert them.
  57.         local inst_user="$(python -c "import pwd; print pwd.getpwuid(int('${PORTAGE_INST_UID:-0}'))[0]")"
  58.         local inst_group="$(python -c "import grp; print grp.getgrgid(int('${PORTAGE_INST_GID:-0}'))[0]")"
  59.         if ! tarsync "${FILE}" "${PORTDIR}" -v -s 1 -o ${inst_user} -g ${inst_group} -e /distfiles -e /packages -e /local; then
  60.             echo "tarsync failed; tarball is corrupt?"
  61.             exit 1;
  62.         fi
  63.         rm "${FILE}"
  64.     else
  65.         if ! tar jxf $FILE; then
  66.             echo "Tar failed to extract the image. Please review the output."
  67.             echo "Executed command: tar jxf $FILE"
  68.             exit 1
  69.         fi
  70.         rm -f $FILE
  71.         # Make sure user and group file ownership is ${PORTAGE_INST_UID}:${PORTAGE_INST_GID}
  72.         chown -R ${PORTAGE_INST_UID:-0}:${PORTAGE_INST_GID:-0} portage
  73.         cd portage
  74.         rsync -av --progress --stats --delete --delete-after \
  75.         --exclude='/distfiles' --exclude='/packages' \
  76.         --exclude='/local' . ${PORTDIR%%/}
  77.         cd ..
  78.         echo "cleaning up"
  79.         rm -rf portage
  80.     fi
  81.     if hasq metadata-transfer ${FEATURES} ; then
  82.         echo "transferring metadata/cache"
  83.         emerge --metadata
  84.     fi
  85. }
  86.  
  87. echo "Fetching most recent snapshot"
  88.  
  89. declare -i attempts=-1
  90. while (( $attempts <  40 )) ; do
  91.     attempts=$(( attempts + 1 ))
  92.  
  93.     #this too, sucks.  it works in the interim though.
  94.     if [ "$USERLAND" == "BSD" ] || [ "$USERLAND" == "Darwin" ] ; then
  95.         daysbefore=$(expr $(date +"%s") - 86400 \* $attempts)
  96.         day=$(date -r $daysbefore +"%d")
  97.         month=$(date -r $daysbefore +"%m")
  98.         year=$(date -r $daysbefore +"%Y")
  99.     else
  100.         day=$(date -d "-$attempts day" +"%d")
  101.         month=$(date -d "-$attempts day" +"%m")
  102.         year=$(date -d "-$attempts day" +"%Y")
  103.     fi
  104.  
  105.     FILE_ORIG="portage-${year}${month}${day}.tar.bz2"
  106.  
  107.     echo "Attempting to fetch file dated: ${year}${month}${day}"
  108.         
  109.     got_md5=0
  110.  
  111.     if [  ! -e "${FILE_ORIG}.md5sum" ]; then
  112.         FILE="${FILE_ORIG}.md5sum"
  113.         for i in $GENTOO_MIRRORS ; do 
  114.             URI="${i}/snapshots/${FILE}"
  115.             if (eval "$FETCHCOMMAND $wgetops") && [ -s "${FILE}" ]; then
  116.                 got_md5=1
  117.                 break
  118.             fi
  119.         done
  120.     else
  121.         got_md5=1
  122.     fi
  123.     FILE="${FILE_ORIG}"
  124.  
  125.     if (($got_md5 == 0 )); then
  126.         echo " --- No md5sum present on the mirror. (Not yet available.)"
  127.         continue
  128.     elif [ -s "${FILE}" ]; then
  129.         if eval "$md5_com"; then
  130.             echo " === snapshot $FILE is correct, using it"
  131.             sync_local
  132.             echo
  133.             echo " === Snapshot has been sync'd"
  134.             echo
  135.             exit 0
  136.         else
  137.             rm $FILE
  138.         fi
  139.     fi
  140.     
  141.     for i in $GENTOO_MIRRORS ; do
  142.         URI="${i}/snapshots/$FILE"
  143.         rm -f "$FILE"
  144.         if (eval "$FETCHCOMMAND $wgetops") && [ -s "$FILE" ]; then
  145.             if ! eval "$md5_com"; then
  146.                 echo "md5 failed on $FILE"
  147.                 rm ${FILE}
  148.                 continue
  149.             else
  150.                 sync_local
  151.                 echo
  152.                 echo " *** Completed websync, please now perform a normal rsync if possible."
  153.                 echo "     Update is current as of the of YYYYMMDD: ${year}${month}${day}"
  154.                 echo
  155.                 exit 0
  156.             fi
  157.         fi
  158.  
  159.     done
  160. done
  161.  
  162. rm -rf portage
  163.  
  164. exit 1
  165.